package cn.ecoinfo.excel.main;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import org.apache.poi.ss.usermodel.Workbook;

import cn.ecoinfo.excel.entity.XMLInfo;
import cn.ecoinfo.excel.service.E2DService;
import cn.ecoinfo.excel.service.impl.E2DServiceImpl;
import cn.ecoinfo.excel.util.DBUtil;
import cn.ecoinfo.excel.util.EXCELUtil;

public class MATest {
	private final static String XMLPATH = "D:\\workspace_my\\EXCEL2DB\\DOCUMENTATION\\EXCEL2DB.xml";
	private final static String EXCELPATH = "D:\\workspace_my\\EXCEL2DB\\DOCUMENTATION\\EXCEL2DB.xlsx";
	public static void main(String[] args) {
		E2DService service = new E2DServiceImpl(); 
		XMLInfo xmlinfo = service.loadXMLTemplate(XMLPATH);
		DBUtil dbutil = new DBUtil(xmlinfo.getDbinfo());
		HashMap parentmap = service.getParents(dbutil, xmlinfo.getParentinfo());
		System.out.println(parentmap);
		Workbook book = EXCELUtil.loadExcel(EXCELPATH);
		List<HashMap> maplist = EXCELUtil.getRows(book, xmlinfo.getExcelinfo());
//		for(int i=0;i<maplist.size();i++){
//			for(Iterator it = maplist.get(i).keySet().iterator();it.hasNext();){
//				String key = (String)it.next();
//				System.out.print(key+"="+maplist.get(i).get(key)+",");
//			}
//			System.out.println();
//		}
		dbutil.importdata(maplist, xmlinfo.getExcelinfo(), xmlinfo.getDbinfo().getTarget(),parentmap);
	}
}

